package com.ygqh.baby.service.impl;

import java.util.Date;
import java.util.List;

import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgPublishAccusation;
import com.ygqh.baby.mapper.YgPublishAccusationMapper;
import com.ygqh.baby.service.YgPublishAccusationService;

import org.springframework.util.Assert;

import java.util.Arrays;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.ygqh.baby.po.YgPublishAccusationExample;
import com.ygqh.baby.ao.DataStatus;

@Service
public class YgPublishAccusationServiceImpl implements YgPublishAccusationService {

	@Autowired
	private YgPublishAccusationMapper ygPublishAccusationMapper;

	@Override
	public List<YgPublishAccusation> find() {
		YgPublishAccusationExample example = new YgPublishAccusationExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygPublishAccusationMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgPublishAccusationExample example = new YgPublishAccusationExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygPublishAccusationMapper.countByExample(example);
	}

	@Override
	public YgPublishAccusation findById(Long id) {
		return ygPublishAccusationMapper.selectByPrimaryKey(id);
	}

	@Override
	public int save(YgPublishAccusation ygPublishAccusation) {
		return ygPublishAccusationMapper.insertSelective(ygPublishAccusation);
	}

	@Override
	public int update(YgPublishAccusation ygPublishAccusation) {
		return ygPublishAccusationMapper.updateByPrimaryKeySelective(ygPublishAccusation);
	}

	@Override
	public ResultSet<YgPublishAccusation> search(QueryInfo queryInfo, String q, String nickName, Date startDate, Date endDate) {
		List<YgPublishAccusation> list = ygPublishAccusationMapper.selectSuper(queryInfo, q, nickName, startDate, endDate);
		int count = ygPublishAccusationMapper.countSuper(q, nickName, startDate, endDate);
		ResultSet<YgPublishAccusation> resultSet = new ResultSet<YgPublishAccusation>(count, list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgPublishAccusationExample example = new YgPublishAccusationExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgPublishAccusation record = new YgPublishAccusation();
		record.setStatus(DataStatus.Delete);

		return ygPublishAccusationMapper.updateByExampleSelective(record, example);
	}

	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[] { id });
	}

	@Override
	public int saveOrUpdate(YgPublishAccusation ygPublishAccusation) {
		int r = 0;
		if (ygPublishAccusation.getId() != null) {
			r = this.update(ygPublishAccusation);
		} else {
			r = this.save(ygPublishAccusation);
		}
		return r;
	}

}
